package com.zhuoshi.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhuoshi.bean.Wd_ht_buildModel;
import com.zhuoshi.bean.Wd_ht_projectModel;
import com.zhuoshi.bean.Wd_purposeModel;
import com.zhuoshi.service.Wd_purposeModelService;

@Controller
@RequestMapping("/purpose")
public class Wd_purposeAction {
	@Autowired
	Wd_purposeModelService wd_purposeModelService ;
	
	@RequestMapping("/selectAll.do")
	public String selectAll(Wd_purposeModel record,Model model){
		List<Wd_purposeModel> list = wd_purposeModelService.selectAll(record);
		model.addAttribute("list", list);
		return "Wd_purpose" ;
	}
	
	@RequestMapping("/Wd_purpose_toAdd.do")
	public String wd_purpose_toAdd(Model model){			
		return "Wd_purpose_add" ;
	}
	
	@RequestMapping("/Wd_purpose_add.do")
	public String wd_purpose_add(Wd_purposeModel record,Model model){	
		wd_purposeModelService.insertSelective(record);
		return "redirect:/purpose/selectAll.do" ;
	}
	
	@RequestMapping("/Wd_purpose_toUpdate.do")
	public String wd_purpose_toUpdate(Wd_purposeModel record,Model model){	
		Wd_purposeModel bean = wd_purposeModelService.selectByPrimaryKey(record.getPurposeId());
		model.addAttribute("bean", bean);
		return "Wd_purpose_update" ;
	}
	
	@RequestMapping("/Wd_purpose_update.do")
	public String wd_purpose_update(Wd_purposeModel record,Model model){	
		wd_purposeModelService.updateByPrimaryKeySelective(record);
		return "redirect:/purpose/selectAll.do" ;
	}
	
	@RequestMapping("/Wd_purpose_delete.do")
	public String wd_purpose_delete(String purposeId){	
		wd_purposeModelService.deleteByPrimaryKey(purposeId);
		return "redirect:/purpose/selectAll.do" ;
	}
	
	@InitBinder
	public void InitBinder(ServletRequestDataBinder binder){
		binder.registerCustomEditor(Date.class, 
				new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
		
	}
}
